USE [Snap]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ExchangeCompany]') AND parent_object_id = OBJECT_ID(N'[dbo].[Companies]'))
ALTER TABLE [dbo].[Companies] DROP CONSTRAINT [FK_ExchangeCompany]
GO

USE [Snap]
GO

/****** Object:  Table [dbo].[Companies]    Script Date: 07/01/2010 13:08:51 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Companies]') AND type in (N'U'))
DROP TABLE [dbo].[Companies]
GO

USE [Snap]
GO

/****** Object:  Table [dbo].[Companies]    Script Date: 07/01/2010 13:08:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Companies](
	[Symbol] [nvarchar](10) NOT NULL,
	[Name] [nvarchar](max) NOT NULL,
	[LastSale] [decimal](18, 0) NULL,
	[MarketCap] [decimal](18, 0) NULL,
	[IpoYear] [int] NULL,
	[Sector] [nvarchar](max) NULL,
	[Industry] [nvarchar](max) NULL,
	[ExchangeName] [nvarchar](10) NOT NULL,
	[SummaryQuoteUrl] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_Companies] PRIMARY KEY CLUSTERED 
(
	[Symbol] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Companies]  WITH CHECK ADD  CONSTRAINT [FK_ExchangeCompany] FOREIGN KEY([ExchangeName])
REFERENCES [dbo].[Exchanges] ([Name])
GO

ALTER TABLE [dbo].[Companies] CHECK CONSTRAINT [FK_ExchangeCompany]
GO


